# _*_ coding:utf-8 _*_
# @Time : 2021/9/17 17:49
# @Author : wsl
# @File : Urllib
# @Project : 简单爬取百度获取信息
import urllib.request

# 模拟浏览器向服务器发送请求
response = urllib.request.urlopen('http://www.baidu.com')
content = response.read().decode('utf-8')
# content = response.read(5)
# content = response.readline()

print(content)
print(type(response))  # HTTPResponse
print(response)
print(response.getcode())  # 200
print(response.geturl())
print(response.getheaders())



url_page = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwx3.sinaimg.cn%2Fmw690%2F00266e0Ply1gtqdqyk3sgg60p00jyhdy02.gif&refer=http%3A%2F%2Fwx3.sinaimg.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1634465063&t=94f6adf425a6c7329091d2c492339f2d'
url_video = 'https://www.douyin.com/aweme/v1/play/?video_id=v0200fg10000cgl7m1rc77u8r2vsov5g&line=0&file_id=558ba3a1505248b6ae39ad837df9dff4&sign=e7295ca75e212d0de85b19c941d42493&is_play_url=1&source=PackSourceEnum_AWEME_DETAIL&aid=6383'

# 下载网页(右键复制图片地址)、视频(元素-video-src的地址就是视频的地址)
urllib.request.urlretrieve(url_page, '../image/output/output.jpg')
urllib.request.urlretrieve(url_video, '../image/output/output.mp4')
